<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>添加文章</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> <link href="/Public/Admin/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="/Public/Admin/css/animate.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.min862f.css?v=4.1.0" rel="stylesheet">
</head>
<style type="text/css">
    .form-group img{
        width: 60px;
        height: 60px;
    }
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="col-sm-8">
                        <div class="ibox float-e-margins">
                        <div class="ibox-title">
                        <h5>添加文章</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="form1" name="form1" action="<?php echo U('article/save');?>" method="post">
                        <input type="hidden" name="id" id="id" value="<?php echo ($data["id"]); ?>">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属栏目：</label>                           
                            <div class="col-sm-3">
                                <select class="form-control m-b" name="cat_id" value="<?php echo ($data["cat_id"]); ?>">
                                <option value="">==请选择栏目==</option>
                                <?php if(is_array($list)): foreach($list as $key=>$vo): ?><option value="<?php echo ($vo["columns"]); ?>" <?php if($vo['columns'] == $data['cat_id'] ): ?>selected<?php endif; ?>><?php echo ($vo['html']); echo ($vo['columns']); ?></option><?php endforeach; endif; ?>
                                </select>
                            </div>
                        </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">文章标题：</label>
                                <div class="col-sm-8">
                                    <input id="title" name="title" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid" value="<?php echo ($data["title"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">文章关键词：</label>
                                <div class="col-sm-8">
                                    <input id="tag" name="tag" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid" value="<?php echo ($data["tag"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">作者：</label>
                                <div class="col-sm-8">
                                    <input id="author" name="author" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid" value="<?php echo ($data["author"]); ?>">
                                </div>
                            </div>
                            <input id="mid" name="mid" type="hidden" value="<?php echo ($mid); ?>">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">发布时间：</label>
                                <div class="col-sm-8">
                                    <input type="text" name="addtime" class="Wdate" type="text" onClick="WdatePicker()" value="<?php echo (date("y-m-d",$data["addtime"])); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">内容：</label>
                                <div class="col-sm-8">
                                    <!-- 加载编辑器的容器 -->
                                <script id="container" name="content" type="text/plain"><?php echo ($data["content"]); ?></script>
                                <!-- 配置文件 -->
                                <script type="text/javascript" src="/Public/Admin//editor/ueditor.config.js"></script>
                                <!-- 编辑器源码文件 -->
                                <script type="text/javascript" src="/Public/Admin//editor/ueditor.all.js"></script>
                                <!-- 实例化编辑器 -->
                                <script type="text/javascript">
                                    var ue = UE.getEditor('container');
                                </script>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">SEO标题：</label>
                                <div class="col-sm-8">
                                    <input id="seo_title" name="seo_title" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid" value="<?php echo ($data["seo_title"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">SEO关键词：</label>
                                <div class="col-sm-8">
                                    <input id="seo_keyword" name="seo_keyword" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid" value="<?php echo ($data["seo_keyword"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">SEO描述：</label>
                                <div class="col-sm-8">
                                    <input id="seo_description" name="seo_description" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error" value="<?php echo ($data["seo_description"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">缩略图：</label>
                                <div class="col-sm-8">
                                    <input id="litpic" name="litpic" class="form-control" type="file" value="<?php echo ($data["litpic"]); ?>">
                                    <img src="<?php echo ($data["litpic"]); ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序：</label>
                                <div class="col-sm-8">
                                    <input id="sort" name="sort" class="form-control" type="text" value="<?php echo ($data["sort"]); ?>">
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-3 control-label">是否生成静态页面：
                                </label>
                                <div class="col-sm-8">
                                    <label class="radio-inline">
                                        <input type="radio" checked="" value="1" id="is_html" name="is_html">静态</label>
                                    <label class="radio-inline">
                                        <input type="radio" value="2" id="is_html" name="is_html">动态</label>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-3 control-label">状态：
                                </label>
                                <div class="col-sm-8">
                                    <label class="radio-inline">
                                        <input type="radio" checked="" value="1" id="status" name="status">正常</label>
                                    <label class="radio-inline">
                                        <input type="radio" value="0" id="status" name="status">禁用</label>
                                </div>
                            </div>
                                <div class="col-sm-16 col-sm-offset-3">
                            <button class="btn btn-primary" id="submit" type="submit">提交</button>
                                </div>
                            </div>                            
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer/layer.min.js"></script>
<script src="/Public/Admin/js/plugins/cropper/cropper.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script src="/Public/Admin/js/common.js"></script>
<script src="/Public/Admin//my97/WdatePicker.js"></script>

<script>
$(function(){
    $.validator.addMethod("checkname",function(value,element,params){
        if(/^[a-zA-Z0-9]{3,16}$/.test(value)){
                return true;
            }else{
                return false;
            }
        },"");
     $("#form1").validate({
            rules: {
                title:"required",
                author:"required",
                addtime:"required",
                content:"required",
                litpic:"required",
                tag:"required",
                seo_title:"required",
                seo_keyword:"required", 
                seo_description:"required", 
                sort:"required",
            },
            messages: {
                title: "请输入文章名名",
                author: "请输入作者名",               
                addtime: "请输入添加时间",
                content: "请输入文章内容",
                litpic:"请上传缩略图",
                tag:"请输入关键词",
                seo_title:"请输入SEO标题",
                seo_keyword:"请输入SEO关键词",
                seo_description:"请输入SEO描述",
                sort:"请输入排序",
            },
            submitHandler: function (form) {
                // var objNames = $(form).serializeArray();
                // var dataNames = new Object();
                // $.each(objNames,function(key,val){
                //     dataNames[val.name] = val.value;
                // });
                var dataform = new FormData(document.getElementById('form1'));
                $.ajax({
                        url:$(form).attr('action'),
                        type:'post',
                        dataType:'json',
                        data:dataform,
                        contentType:false,//避免ajax添加Content-Type头，导致上传失败，必须写
                        processData:false,//告诉ajax不要处理数据，必须写
                        success:function(data){
                           if(data.status > 0){
                               common.error(data.msg);
                           }else{
                               common.success(data.msg,"<?php echo U('article/index');?>");
                           }
                        }
                });
            }
        });
});
</script>       
</body>
</html>